﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act))
	{
		if (empty($kptype) || empty($kpdesc) || empty($kpowner) ||empty($kpnum) ||empty($kppn) || empty($kpstat) || $kptype == "N/A" ){
			echo "<script>alert('有内容不能未空或类型为默认值，请重新填写');window.history.go(-1);</script>";
			die("有内容不能未空或类型为默认值，请重新填写");
		}
		if (empty($kpremark))
			$kpremark='N/A';

		if ($act == 'add')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$dt = date("Y-m-d H:i:s");
			$db = new mysql();
			$sql="INSERT INTO `eng_repo` (`KP_TYPE`, `KP_PN`, `KP_DESC`, `KP_NUM`, `DEPT`, `KP_OWNER`, 
				`STATUS`, `REMARK`) values('".htmlentities($kptype,ENT_QUOTES)."', '".htmlentities($kppn,ENT_QUOTES)."', 
					'".htmlentities($kpdesc,ENT_QUOTES)."', '".htmlentities($kpnum,ENT_QUOTES)."', '".$iDept."', '"
				.htmlentities($kpowner,ENT_QUOTES)."', '".htmlentities($kpstat,ENT_QUOTES)."', '".htmlentities($kpremark,ENT_QUOTES)."')";
			$db->query($sql);
			$db->close();
			echo "<script>alert('数据添加完成!');window.opener.location.reload();window.close();</script>";
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script>
	$(function(){
		$("#addbtn").click(function(){
			if ($("#kppn").val() == ""){
				alert("料号没有填写！");
				return false;
			}

			if ($("#kpdesc").val() == ""){
				alert("料号描述没有填写！");
				return false;
			}

			if ($("#kpnum").val() == ""){
				alert("数量没有填写！");
				return false;
			}			

			if ($("#kpowner").val() == ""){
				alert("保管人没有填写！");
				return false;
			}
		});
	});
</script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>添加管控内容</title>
</head>
<body class="background">
<?	include "admin_top.php";?>
<div class="container white-background pagecontent">
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">添加管控内容</h3>
    </div>
    <div class="panel-body">
	<form action="add_repo.php?act=add" method="post">
	<div class="input-group">
		<span class="input-group-addon">类型:</span>
		<select name="kptype" id="kptype" class="form-control">
			<option value="N/A">---</option>
			<option value="整机">整机</option>
			<option value="重材">重材</option>
			<option value="机构">机构</option>
			<option value="电子">电子</option>
			<option value="主板">主板</option>		
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">料号:</span>
		<input name="kppn" id='kppn' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">描述:</span>
		<input name="kpdesc" id='kpdesc' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">数量:</span>
		<input name="kpnum" id='kpnum' type="text" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">状态:</span>
		<select name="kpstat" id="kpstat" class="form-control">
			<option value="借用中">借用中</option>
			<option value="已归还">已归还</option>
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">部门:</span>
		<select name="iDept" id="iDept" class="form-control">
			<option value="TE">TE</option>
			<option value="ME">ME</option>
			<option value="EE">EE</option>
			<option value="RT">RT</option>
			<option value="PE">PE</option>		
			<option value="IE">IE</option>					
			<option value="FPM">FPM</option>
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">保管人:</span>
		<input name="kpowner" id='kpowner' type="text" class="form-control">
	</div>
	<div>备注:<br />
		<textarea name="kpremark" id="kpremark" rows="12" cols="60" class="xheditor {tools:'mini',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:280px; no-repeat right bottom fixed">
		</textarea>
	</div>
	<div>	<input class="btn btn-success btn-primary" name="submit" value="提交" type="submit" id='addbtn'>
		<input class="btn btn-danger" name="reset" value="重填" type="reset"></div>
</form>
</div>
</div>
</div>
<?
include '../bottom.php';
?>
</body>
</html>
